package com.netsdk.demo.frame.Gate;

import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.sun.jna.Memory;
import com.sun.jna.Pointer;

import java.io.File;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 47081
 * @version 1.0
 * @description 人脸识别一体机封包定制
 * 功能需求
 * 1.下发二维码到设备
 * 2.图片视频上传到设备
 * 3.广告播放内容下发到设备
 * 4.全屏广告模式配置
 * 5.广告禁播时间段配置
 * 6.人员、卡号、人脸下发一体机
 * 7.同步本地人员健康码信息
 * 8.配置健康码
 * @date 2020/9/16
 */
public class FaceGateHealth {
    private static NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE;
    private static long loginHandler;
    /**
     * 登录设备
     *
     * @param ip
     * @param port
     * @param username
     * @param password
     * @return
     */
 /*   public boolean login(String ip, int port, String username, String password) {
        info = baseModule.login(ip, port, username, password);
        loginHandler = info.getLoginHandler();
        if (loginHandler == 0) {
            System.out.println("login failed." + ENUMERROR.getErrorMessage());
            return false;
        }
        return true;
    }*/

    /**
     * 下发二维码到设备
     *
     * @param type 二维码类型
     * @param code 二维码字符串
     * @return
     */
/*    public boolean sendQRCode(NET_EM_2DCODE_TYPE type, String code) {
        boolean result = qrCodeModule.sendQrCode(loginHandler, type, code);
        if (!result) {
            System.out.println("send qrcode is error." + ENUMERROR.getErrorMessage());
        } else {
            System.out.println("sen qrcode successed");
        }
        return result;
    }

    public void sendCode() {
        sendQRCode(NET_EM_2DCODE_TYPE.NET_EM_2DCODE_TYPE_VIDEOTALK, "1234232aaaa");
    }*/
    /**
     * 同步本地健康码信息
     */
    public static void openDoorByFace() {
        //入参
        NetSDKLib.NET_IN_FACE_OPEN_DOOR pInParam = new NetSDKLib.NET_IN_FACE_OPEN_DOOR();
        pInParam.nChannel = 0;
        //比对结果需要填正数
        pInParam.emCompareResult = 1;
        byte[] UserID = "3".getBytes();
        System.arraycopy(UserID, 0, pInParam.stuMatchInfo.szUserID, 0, UserID.length);

        NetSDKLib.NET_HEALTH_CODE_INFO health_code_info = new NetSDKLib.NET_HEALTH_CODE_INFO();
        health_code_info.emHealthCodeStatus = NetSDKLib.EM_HEALTH_CODE_STATUS.EM_HEALTH_CODE_STATUS_GREEN.ordinal();
        pInParam.stuMatchInfo.pstuHealthCodeInfo = new Memory(health_code_info.size());
        ToolKits.SetStructDataToPointer(health_code_info, pInParam.stuMatchInfo.pstuHealthCodeInfo, 0);

        //出参
        NetSDKLib.NET_OUT_FACE_OPEN_DOOR pOutParam = new NetSDKLib.NET_OUT_FACE_OPEN_DOOR();

        boolean bRet = netsdk.CLIENT_FaceOpenDoor(new NetSDKLib.LLong(loginHandler), pInParam, pOutParam, 3000);
        if (!bRet) {
            //System.out.println("face open door failed." + ENUMERROR.getErrorMessage());
            return;
        } else {
            System.out.println("同步健康码成功");
        }
    }

    /**
     * 获取健康码配置
     */
/*    public void getHealthCodeConfig() {
        NET_CFG_HEALTH_CODE_INFO info = (NET_CFG_HEALTH_CODE_INFO) configModule.getConfig(loginHandler, NetSDKLib.NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_HEALTH_CODE, new NET_CFG_HEALTH_CODE_INFO(), -1);
        if (info != null) {
            System.out.println(info.toString());
        }
    }*/
    /**
     * 下发健康码配置
     */
/*    public void setHealthCodeConfig() {
        NET_CFG_HEALTH_CODE_INFO info = new NET_CFG_HEALTH_CODE_INFO();
        info.bEnable = true;
        info.bOfflineEnable = true;
        info.bQRCodeReaderEnable = true;
        if (!configModule.setConfig(loginHandler, NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_HEALTH_CODE, info, -1)) {
            System.out.println("配置健康码失败," + ENUMERROR.getErrorMessage());
        }
    }*/
/*    public static void main(String[] args) {
        String ip = "172.5.4.179";
        int port = 37777;
        String username = "admin";
        String password = "admin123";
        FaceGateHealth demo = new FaceGateHealth();
        if (demo.login(ip, port, username, password)) {
            demo.runTest();
        }
        demo.logout();

    }*/

}
